﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Gameserver.Tools
{
    public delegate void EvenExcuteDE();
    /// <summary>
    /// 用于锁住客户端，不让同个账户在多地点登陆
    /// </summary>
    class EventExcuteUtil
    {
        public Mutex mutex;
        private static EventExcuteUtil instance;
        public static EventExcuteUtil Instance {
            get {
                if (instance == null)
                {
                    instance = new EventExcuteUtil();
                }
                return instance;
            }
        }
        private EventExcuteUtil()
        {
            mutex = new Mutex();
        }
        public void Excute(EvenExcuteDE de)
        {
            lock(this)
            {
                mutex.WaitOne();
                de();
                mutex.ReleaseMutex();
            }
        }
    }
}
